<?php

namespace app\admin\model;

use think\migration\command\seed\Run;
use think\Model;
use app\admin\model\User;

class Orders extends Model
{

    protected $append =[
      'status_str'
    ];
    // 表名
    protected $name = 'cloudphone_order';

    public function user(){
        return $this->belongsTo("user",'user_id','id');
    }
    public function phone(){
        return $this->belongsTo("cloudphone",'phone_id','id');
    }

    const STATUS_WAITPAY = 1000;
    const STATUS_HASPAY  = 2000;
    const STATUS_HASFINISH = 3000;
    const STATUS_HASCLOSE = 8000;
    public function statusList(){
        return [
            ['id'=>self::STATUS_WAITPAY,'name'=>'待付款'],
            ['id'=>self::STATUS_HASPAY,'name'=>'已付款'],
            ['id'=>self::STATUS_HASFINISH,'name'=>'已完成'],
            ['id'=>self::STATUS_HASCLOSE,'name'=>'已关闭'],
        ];
    }
    public function statusList2(){
        return [
            self::STATUS_WAITPAY=>'待付款',
            self::STATUS_HASPAY=>'已付款',
            self::STATUS_HASFINISH=>'已完成',
            self::STATUS_HASCLOSE=>'已关闭',
        ];
    }

    public function getStatusColor()
    {

        return [
            self::STATUS_WAITPAY=>'bg-teal',
            self::STATUS_HASPAY=>'label-primary',
            self::STATUS_HASFINISH=>'bg-green',
            self::STATUS_HASCLOSE=>'bg-red',
        ];
    }

    public function getStatusStrAttr($value, $data){
        $status = $data['status'];
        $statusList = self::statusList2();
        return $statusList[$status];
    }
}
